<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>06绝对定位居中</title>
    <style>
        .box {
            position: relative;
            width: 1200px;
            height: 800px;
            background-color: #ff00ff;
        }

        .form-div {
            position: absolute;
            width: 500px;
            height: 300px;
            background-color: #ffff00;
            /* 下面三行代码用于居中 */
            /* top: 50%; */
            left: 50%;
            transform: translate(-50%,0);
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="form-div">
            居中的重要代码：
            position: absolute;<br>
            top: 50%;<br>
            left: 50%;<br>
            transform: translate(-50%,-50%);<br>
        </div>
    </div>
</body>
</html>